function ajaxFn(url, successFn) {
    const xhr = new XMLHttpRequest();
    xhr.open("GET", url, true);
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                successFn && successFn(xhr.responseText);
            } 
        }
    }
    xhr.send(null);
}

// Promise版本ajax
function promiseAjaxFn(url) {
    return new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest();
        xhr.open("GET", url, true);
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    resolve(JSON.parse(xhr.responseText));
                } else if (xhr.status === 404) {
                    reject("url 404");
                }
            }
        }
        xhr.send(null);
    })
}

promiseAjaxFn("url").then( res => {}).catch(err => console.log(err));